package com.class05.listener;

import javax.servlet.*;
import javax.servlet.annotation.WebListener;
import javax.servlet.http.HttpServletRequest;
@WebListener
public class MyHttpServletRequestListener implements
        ServletRequestListener , ServletRequestAttributeListener {
//   往请求中添加属性时，会触发该方法
    @Override
    public void attributeAdded(ServletRequestAttributeEvent srae) {
//        获取请求域
        HttpServletRequest servletRequest =
                (HttpServletRequest) srae.getServletRequest();
//        获取请求的URI
        System.out.println("请求的URL为：" + servletRequest.getRequestURI());
//        获取添加的属性名和值
        System.out.println("往请求中添加了属性：" + srae.getName()
                + "，值为：" + srae.getValue());

    }
    //   往请求中删除属性时，会触发该方法

    @Override
    public void attributeRemoved(ServletRequestAttributeEvent srae) {
        System.out.println("删除了属性名为：" + srae.getName());
    }
    //   往请求中替换属性时，会触发该方法
    @Override
    public void attributeReplaced(ServletRequestAttributeEvent srae) {
        System.out.println("修改了属性名为：" + srae.getName());
    }

//    请求被销毁时，会触发该方法
    @Override
    public void requestDestroyed(ServletRequestEvent sre) {
        System.out.println("ServletRequestListener监听器监听到请求被销毁了");
    }

//    请求被初始化时，会触发该方法

    @Override
    public void requestInitialized(ServletRequestEvent sre) {
        System.out.println("ServletRequestListener监听器监听到请求被初始化了");
    }
}
